<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Supplier extends Model
{
    use HasFactory;


    protected $fillable = [
        'user_id','name', 'tax_id', 'address', 'mobile', 'bank', 'bank_number', 'bank_account', 'email', 'postal_code', 'authorize_file', 'business_file', 'idcard_file', 'agent_idcard_file', 'legal', 'legal_mobile', 'agent', 'agent_mobile'
    ];

    const POSTONLY = [
        'user_id','name', 'tax_id', 'address', 'mobile', 'bank', 'bank_number', 'bank_account', 'email', 'postal_code', 'authorize_file', 'business_file', 'idcard_file', 'agent_idcard_file', 'legal', 'legal_mobile', 'agent', 'agent_mobile'
    ];


    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function user()
    {
        return $this->hasOne(User::class,'id','user_id')->select('id','name');
    }

    public function application()
    {
        return $this->hasOne(Application::class,'source_id','id')->where('model','Supplier')->orderBy('id','desc');
    }

}
